const fs = require('fs')
const path = require('path')
const lessToJs = require('less-vars-to-js')
const theme = lessToJs(fs.readFileSync(path.join(__dirname, './src/theme.less'), 'utf8'))
const lessVaribles = "proc" // 打包引用less变量 ""=默认版本(default); "adv"=高级版本; "proc"=高检院版本。

module.exports = {
  // Project deployment base
  // By default we assume your app will be deployed at the root of a domain,
  // e.g. https://www.my-app.com/
  // If your app is deployed at a sub-path, you will need to specify that
  // sub-path here. For example, if your app is deployed at
  // https://www.foobar.com/my-app/
  // then change this to '/my-app/'
  baseUrl: './',
  // baseUrl: '/ocr-ui/', //用于本地运行在客户端试跑

  // where to output built files
  outputDir: 'dist',

  // whether to use eslint-loader for lint on save.
  // valid values: true | false | 'error'
  // when set to 'error', lint errors will cause compilation to fail.
  lintOnSave: true,

  // tweak internal webpack configuration.
  // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  chainWebpack: () => {},
  configureWebpack: {
    module: {
      rules: [],
    },
    resolve: {
      extensions: ['.js', '.jsx', '.vue'],
      alias: {
        vue$: 'vue/dist/vue.esm.js',
      },
    },
  },

  // generate sourceMap for production build?
  productionSourceMap: true,

  // CSS related options
  css: {
    // enable CSS source maps?
    sourceMap: false,

    // pass custom options to pre-processor loaders. e.g. to pass options to
    // sass-loader, use { sass: { ... } }
    loaderOptions: {
      less: {
        modifyVars: theme,
        javascriptEnabled: true,
      },
    },

    // Enable CSS modules for all css / pre-processor files.
    // This option does not affect *.vue files.
    modules: false,
  },

  // use thread-loader for babel & TS in production build
  // enabled by default if the machine has more than 1 cores
  parallel: require('os').cpus().length > 1,

  // options for the PWA plugin.
  // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  pwa: {},

  // configure webpack-dev-server behavior
  devServer: {
    open: process.platform === 'darwin',
    host: '0.0.0.0',
    port: 8080,
    https: false,
    hotOnly: false,
    // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#configuring-proxy
    proxy: null, // string | Object
    before: () => {},
  },

  // options for 3rd party plugins
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        path.resolve(__dirname, (lessVaribles=='adv'?'./src/assets/lessVaribles/adv.less':(lessVaribles=='proc'?'./src/assets/lessVaribles/proc.less':'./src/assets/lessVaribles/default.less')))
      ]
    }
  },
}
